IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UpdateAnimalBoardStagingData]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[UpdateAnimalBoardStagingData]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



/***************************************************************************
* Name:			UpdateAnimalBoardStagingData
* Purpose:		Using table Stg_AnimalBoards, update Org and Person IDs from Asset
*
* PARAMETERS
* Name				Description					
* -------------		-----------------------------------------------------------
* n/a
*
* ERRORS USED		Description			
* -------------		-----------------------------------------------------
* n/a
*
* RETURN VALUE
* Value    			Description					
* --------------	------------------------------------------------------
***************************************************************************/
CREATE PROCEDURE dbo.UpdateAnimalBoardStagingData
AS
BEGIN


	SET NOCOUNT ON

	UPDATE	Stg_AnimalBoards
	SET		IRBBoardTypeId = IRBBoardType.Id
	FROM	IRBBoardType
	WHERE	Stg_AnimalBoards.sGroupType = IRBBoardType.Name

	-- Org
	UPDATE  Stg_AnimalBoards
	Set		InstitutionID = FwkDomainOrganization.Id 
	FROM	FwkDomainOrganization
	WHERE	Stg_AnimalBoards.sPIInstitution = FwkDomainOrganization.Name
			AND FwkDomainOrganizationTypeId = 2

	-- If it's IACUC, set the sequence to 1, otherwise, set it to 99
	UPDATE	Stg_AnimalBoards SET SequenceID = 1 WHERE sDescription LIKE '%IACUC%'
	UPDATE	Stg_AnimalBoards SET SequenceID = 99 WHERE SequenceId IS NULL


	SET NOCOUNT OFF

	END

GO
